<template name="limit">
  <view class="limit">
    <view class="bgs_top">
      <view class="navigation">
        <image class="navigationIcon" src="../../static/p_back.png" mode="" @click="navigateBack"></image>
        <text class="navigationText">Loan Details</text>
      </view>
    </view>
    <view class="main">
      <view class="box">
        <view class="name">Loanable amount</view>
        <view class="number">₹{{ amount }}</view>
      </view>
      <view class="box">
        <view class="title">Loan details</view>
        <view class="filed" v-for="(itm, idx) in labelOption" :key="idx">
          <view class="label">{{ itm.label }}</view>
          <view class="value"> {{ itm.value }}</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import $_storage from '../../common/util/storage';
import { getDecryptString } from '../../defaut';
export default {
  name: 'limit',
  data() {
    const authentication4 = $_storage.getStorage('authentication_4');
    const infodata = {
      loanable_amount: authentication4 ? authentication4.loanable_amount : 0,
      loan_month: authentication4 ? authentication4.loan_term : 0,
      replayment: authentication4 ? authentication4.repayment : 0,
      total_interest: authentication4 ? authentication4.total_interest : 0,
      monthly_interest: authentication4 ? authentication4.monthly_interest : 0,
      monthly_repayment: authentication4 ? authentication4.monthly_repayment : 0,
    };
    return {
      amount: infodata.loanable_amount,
      labelOption: [
        {
          label: 'Loan term (month)',
          value: infodata.loan_month,
          key: 'term',
        },
        {
          label: 'Total interest',
          value: infodata.total_interest,
          key: 'interest',
        },
        {
          label: 'Repayment',
          value: infodata.replayment,
          key: 'repayment',
        },
        {
          label: 'Monthly Interest:',
          value: infodata.monthly_interest,
          key: 'monthly_interest',
        },
        {
          label: 'Monthly Repayment(EM):',
          value: infodata.monthly_repayment,
          key: 'monthly_repayment',
        },
      ],
    };
  },
  methods: {
    // 返回
    navigateBack() {
      uni.navigateBack({
        delta: 1
      })
    },
    // 获取数据
    async getData() {
      const res = await this.$http.get("/user/v1/getcurruser", {})
      // console.log(res);
      if (res.data.status == 200) {
        let arr = JSON.parse(getDecryptString(res.data.data, this.$password()));
        // console.log(arr);
		this.amount=arr.loanAmount
        for (const key in arr) {
          this.labelOption.map((el) => {
            if (el.key == key) {
				if(key=='term'){
					 el.value = arr[key]/30
				}else{
					 el.value = arr[key]
				}
             
            }
          })
        }
      }
    }
  },

  mounted() {
    this.getData()
  }
};
</script>

<style scoped>
page {
  min-height: 100vh;
  padding-bottom: 24rpx;
}

/* .limit {
  width: 100%;
  min-height: 100vh;
  background: rgba(245, 245, 245, 1);

  .bgs_top {
    height: 200rpx;
    border-radius: 0rpx 0rpx 24rpx 24rpx;
    background: rgba(214, 48, 49, 1);
  }

  .main {
    width: 100%;
    padding: 0 24rpx;

    .box {
      width: 100%;
      background: #fff;
      border-radius: 16rpx;
      min-height: 20rpx;
      min-height: 240rpx;

      .name {
        font-size: 30rpx;
        color: #000;
        font-weight: bold;
      }

      .number {
        margin-top: 16rpx;
        font-size: 80rpx;
        font-weight: 400;
        color: rgba(255, 122, 101, 1);
      }

      .title {
        line-height: 70rpx;
        font-size: 36rpx;
        font-weight: bold;
        color: #000;
      }

      .filed {
        display: flex;
        align-items: center;
        justify-content: space-between;
        line-height: 50rpx;
        font-size: 24rpx;

        &>.label {
          color: #999;
        }

        &>.value {
          color: #000;
          font-weight: bold;
        }
      }

      &:nth-child(1) {
        margin-top: -150rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
      }

      &:nth-child(2) {
        margin-top: 40rpx;
        padding: 16rpx 24rpx 24rpx;
      }
    }
  }
} */
.navigation {
  display: flex;
  align-items: center;
  text-align: center;
  padding: 80rpx 26rpx 20rpx;
  position: sticky;
  background: rgba(214, 48, 49, 1);
  top: 0;
  z-index: 10;

}

.navigationIcon {
  width: 22rpx;
  height: 38rpx;
}

.navigationText {
  width: 100%;
  font-size: 38rpx;
  font-weight: 400;
  color: #ffffff;
  line-height: 54rpx;
  letter-spacing: 2rpx;
}

.limit {
  width: 100%;
  min-height: 100vh;
  background: rgba(245, 245, 245, 1);
}


.limit .bgs_top {
  height: 350rpx;
  border-radius: 0rpx 0rpx 24rpx 24rpx;
  background: rgba(214, 48, 49, 1);
}

.limit .main {
  width: 100%;
  padding: 0 24rpx;
}

.limit .main .box {
  width: 100%;
  background: #fff;
  border-radius: 16rpx;
  min-height: 20rpx;
  min-height: 280rpx;
}

.limit .main .box .name {
  font-size: 38rpx;
  color: #000;
  font-weight: 400;
}

.limit .main .box .number {
  margin-top: 28rpx;
  font-size: 80rpx;
  font-weight: 400;
  color: rgba(255, 122, 101, 1);
}

.limit .main .box .title {
  line-height: 70rpx;
  font-size: 36rpx;
  font-weight: 400;
  color: #000;
}

.limit .main .box .filed {
  display: flex;
  align-items: center;
  justify-content: space-between;
  line-height: 60rpx;
  font-size: 32rpx;



  &>.value {
    color: #000;
    font-weight: bold;
  }
}

.limit .main .box .filed>.label {
  color: #999;


}

.limit .main .box .filed>.value {
  color: #000;

  font-weight: 400;
}

.limit .main .box:nth-child(1) {
  margin-top: -150rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.limit .main .box:nth-child(2) {
  margin-top: 40rpx;
  padding: 16rpx 24rpx 24rpx;
}

/* 头部额度部分 */
</style>
